<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
	/*
	 This file used to check login status and show login page 
	 and will be used in all pages of the admin system.
	*/
	
	//Load from Cookie 
	if (isset($_COOKIE['gcms'])) {
	    foreach ($_COOKIE['gcms'] as $name => $value) {
	        $_SESSION[$name] = $value;  
	    }
	}
	 
	 
	if(!isset($_SESSION['user_id']) || $_SESSION['user_id'] == "") {
		if(isset($_SESSION['error'])) {
			$smarty->assign("login_msg", $_SESSION['error']);
		}
		if(isset($_GET['page']) && $_GET['page'] == 'forgotpass')
			$smarty->display("forgotpass.tpl");
		else
			$smarty->display("login.tpl");
			
		if(isset($_POST['action']) && $_POST['action'] == 'forgot_pass'){
			include_once("controller/BgcmsUser.class.php");
			require_once("model/BgcmsUserBean.class.php");
			include_once("controller/BgcmsEmail.class.php");
			$forgotpass = new BgcmsUser($db, $smarty);
			$forgotpass->forgotpass();
		}
			
		ob_end_flush();
		
		unset($_SESSION['user_id']);
		unset($_SESSION['user_name']);
		unset($_SESSION['error']);
		unset($_SESSION['user_isadmin']);
		
		die;
	}
?>
